<?php

/*
 * $Author ：PHPYUN开发团队
 *
 * 官网: http://www.phpyun.com
 *
 * 版权所有 2009-2019 宿迁鑫潮信息技术有限公司，并保留所有权利。
 *
 * 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class crm_dealsp_controller extends adminCommon
{

    function index_action()
    {
        
        $auid   = intval($_SESSION['auid']);
        
        $orderM = $this->MODEL('companyorder');

        $where  = $urlarr = array();

        $where['crm_uid']       =   array('<>','');
        
        if ($_GET['order_id']) {
            
            $where['order_id']  =   trim($_GET['order_id']);
            $urlarr['order_id'] =   $_GET['order_id'];
        }

        $urlarr['page'] =   "{{page}}";
        $pageurl        =   Url($_GET['m'], $urlarr, 'admin');
        $pageM          =   $this->MODEL('page');
        $pages          =   $pageM->pageList('company_order', $where, $pageurl, $_GET['page']);

        if ($pages['total'] > 0) {

            if ($_GET['order']) {

                $where['orderby']   =   $_GET['t'] . ',' . $_GET['order'];
                $urlarr['order']    =   $_GET['order'];
                $urlarr['t']        =   $_GET['t'];
            } else {

                $where['orderby']   =   array('order_state, ASC', 'id, DESC');
            }

            $where['limit']         =   $pages['limit'];
            $orders                 =   $orderM -> getList($where, array('utype' => 'crmdealsp'));
        }

        $ratingM    =   $this->MODEL('rating');
        $ratinglist =   $ratingM->getList(array('category' => '1'), array('field' => '`id`,`name`'));

        $cacheM     =   $this->MODEL('cache');
        $cache      =   $cacheM->GetCache(array('crm'));

        $this->yunset(array('orders' => $orders, 'ratinglist' => $ratinglist, 'cache' => $cache));
        $this->yuntpl(array('admin/crm_dealsp_list'));
    }
    
    /**
     * @desc 审批订单详细
     */
    function getOrderInfo_action(){
        
        $orderM =   $this->MODEL('companyorder');
        
        $id     =   $_GET['id'];
        
        $orderInfo  =   $orderM -> getInfo(array('id' => $id));
        
        $adminM =   $this -> MODEL('admin');
        
        $auser  =   $adminM -> getAdminUser(array('uid' => $orderInfo['crm_uid']));
        
        $ratingM    =   $this -> MODEL('rating');
        
        $ratingArr  =   $ratingM -> getInfo(array('id' => $orderInfo['rating']), array('field' => '`id`,`name`'));
        
        $this->yunset(array('orderInfo' => $orderInfo, 'aname' => $auser['name'], 'ratingName' => $ratingArr['name']));
        
        $this->yuntpl(array('admin/crm_order_info'));
    }
    
    /**
     * @desc 修改订单
     */
    function setOrder_action(){
       
        $id			=	intval($_POST['id']);
        $OrderM		=	$this -> MODEL('companyorder');
        
        $mData      =   array(
            'order_price'		=>  $_POST['order_price'],
            'order_remark'		=>  $_POST['order_remark']
        );
        
        $return		=	$OrderM  ->  upInfo($id, $mData);
     
        $this -> ACT_layer_msg($return['msg'],$return['errcode'],"index.php?m=crm_dealsp");
    }
    
    /**
     * @desc 确认订单，收款
     */
    function setpay_action(){
        
        $this -> check_token();
        $id			=	intval($_GET['id']);
        $OrderM		=	$this -> MODEL('companyorder');
        $return		=	$OrderM -> setPay($id);
        $this -> layer_msg($return['msg'],$return['errcode'],0,$_SERVER['HTTP_REFERER']);
    }
    
    /**
     * @desc 订单删除
     */
    function del_action(){
        
        $this -> check_token();
        $id			=	intval($_GET['id']);
        $OrderM		=	$this -> MODEL('companyorder');
        $return		=	$OrderM -> del($id,array('utype'=>'admin'));
        $this -> layer_msg($return['msg'],$return['errcode'],0,$_SERVER['HTTP_REFERER']);
    }
}
?>